<?php

include('../includes/smarty.php');
include_once('../config.php');

session_start();

$ADMIN = new Admin();
$EMPLOYER = new Employer();
$INDUSTRY = new Industry();

if(isset($_SESSION["id"]))
{
	//	Validate the session.
	$row = $ADMIN->validate_admin_session($_SESSION["id"]);
	
	if($row)
	{
		//	Show the screen.
		$ADMIN->update_lastvisit($_SESSION["id"]);
		
		//	Get the existing companies.
		$companies = $EMPLOYER->get_companies();
		
		if(empty($_POST))
		{
			$smarty->assign('phoneREX', 	$regex_phone);
			$smarty->assign('emailREX', 	$regex_email);	
			$smarty->assign('title', 		'Admin: Add contact information');
			$smarty->assign('path', 		$site);
			$smarty->assign('body', 		'main/admin/contact.tpl');
			$smarty->assign('companylist', 	$companies);
			$smarty->assign('message',		'');

			$smarty->display('admin.tpl');
		}
		else
		{
			//	Posting a new submission.	
			
			$fk_employer_id = $_POST["txt_employer"];	//posts employer
			$fname = $_POST["txt_fname"];				//posts contact first name
			$lname = $_POST["txt_lname"];				//posts contact last name
			$phone_number = $_POST["txt_phone1"];		//posts contact phone number
			$fax_number = $_POST["txt_fax1"];			//posts contact fax number
			$email_address = $_POST["txt_email1"];		//posts contact email address
			
			$EMPLOYER->add_contact($fk_employer_id, $fname, $lname, $phone_number, $fax_number, $email_address);
			
			//	Success
			
			$smarty->assign('phoneREX', 	$regex_phone);
			$smarty->assign('emailREX', 	$regex_email);	
			$smarty->assign('title', 		'Admin: Add contact information');
			$smarty->assign('path', 		$site);
			$smarty->assign('body', 		'main/admin/contact.tpl');
			$smarty->assign('companylist', 	$companies);
			$smarty->assign('message',		'');
			$smarty->assign('message',		'Successfully posted the new job.');

			$smarty->display('admin.tpl');
		}
	}
	else
	{
		//	Kill the current session, and show the login screen.
		session_destroy();
		header('Location: ../admin');
	}
}

?>